package com.manage.dao;

import com.manage.domain.Student;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface IStudentDao {

    @Insert({
            "insert into student(name, no, gender, phone, id_card, is_college, address, degree, graduation_date, clazz_id)",
            "values(#{name},#{no},#{gender},#{phone},#{idCard},#{isCollege},#{address},#{degree},#{graduationDate},#{clazzId})"
    })
    void insert(Student s);

    @Update({
            "<script>",
            "update student",
            "<set>",
            "<if test=\"name != null and name != ''\">name = #{name},</if>",
            "<if test=\"no != null and no != ''\">no = #{no},</if>",
            "<if test=\"gender != null\">gender = #{gender},</if>",
            "<if test=\"phone != null and phone != ''\">phone = #{phone},</if>",
            "<if test=\"idCard != null and idCard != ''\">id_card = #{idCard},</if>",
            "<if test=\"isCollege != null\">is_college = #{isCollege},</if>",
            "<if test=\"address != null and address != ''\">address = #{address},</if>",
            "<if test=\"graduationDate != null\">graduation_date = #{graduationDate},</if>",
            "<if test=\"degree != null\">degree = #{degree},</if>",
            "<if test=\"violationCount != null\">violation_count = #{violationCount},</if>",
            "<if test=\"violationScore != null\">violation_score = #{violationScore},</if>",
            "<if test=\"clazzId != null\">clazz_id = #{clazzId},</if>",
            "<if test=\"updateTime != null\">update_time = #{updateTime}</if>",
            "</set>",
            "where id = #{id}",
            "</script>"
    })
    void update(Student s);

    @Delete({
            "<script>",
            "delete from student where id in",
            "<foreach collection='ids' item='id' separator=',' open='(' close=')'>",
            "#{id}",
            "</foreach>",
            "</script>"
    })
    void deleteBatch(@Param("ids") List<Integer> ids);

    @Select({
            "select s.*, c.name clazzName from student s left join clazz c on s.clazz_id = c.id",
            "order by s.update_time desc"
    })
    List<Student> list();
}


